package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.DealerAttachmentPolicyModel;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * Created by sxy on 2016/7/13.
 */
public interface DealerAttachmentPolicyRepository extends JpaRepository<DealerAttachmentPolicyModel, Integer>, JpaSpecificationExecutor<DealerAttachmentPolicyModel> {

//     需要修改的方法
    @Modifying
    @Query("update DealerAttachmentPolicyModel u set u.status = ?3 where u.permit = ?1")
    int setStatusByPermitAndDealerSiNumber(String permit, Integer dealerSiNumber, String status);
    

    @Modifying
    @Query("update DealerAttachmentPolicyModel u set u.status = ?1 where u.itemCount=?2 and u.permit = ?3 and u.status<>3 ")
    int updDealerAttachmentPolicyStatu(String status, Integer itemCount, String permit);

    @Modifying
    @Query("update DealerAttachmentPolicyModel u set u.status='3' where u.itemCount=?1 and u.permit =?2 ")
    int delDealerAttachmentPloicy(Integer itemCount, String permit);

    @Query("select u.itemCount from DealerAttachmentPolicyModel u where u.id=?1")
    Integer selectDealerAttachmentById(Integer id);
}
